using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using SampleModels;

var builder = WebApplication.CreateBuilder(args);

AutoConfiguration.Configure(builder.Services);

builder.Services.AddDbContext<DataDbContext>((sp, options) => { sp.AutoConfigure<DataDbContext>(options); });

//builder.Services.AddDbContextPool<DataDbContext>((sp, options) => { sp.AutoConfigure<DataDbContext>(options); });
//builder.Services.AddDbContextFactory<DataDbContext>((sp, options) => { sp.AutoConfigure<DataDbContext>(options); });
//builder.Services.AddPooledDbContextFactory<DataDbContext>((sp, options) => { sp.AutoConfigure<DataDbContext>(options); });

var app = builder.Build();

app.MapGet("/", async ([FromServices] DataDbContext context) => {
    await context.Database.EnsureCreatedAsync();
    var count = await context.Persons.CountAsync();

    return count;
});

app.Run();
